<?php TPL::output('admin/global/header.tpl.htm'); ?>
<?php TPL::output('admin/global/nav_menu.tpl.htm'); ?>

<div class="aw-content-wrap">
    <div class="mod">
        <div class="mod-head">
            <h3>
                <ul class="nav nav-tabs">
                    <li><a href="admin/weixin/sent_msgs_list/"><?php _e('群发列表'); ?></a></li>
                    <li class="active"><a href="admin/weixin/send_msg_batch/"><?php _e('群发消息'); ?></a></li>
                </ul>
            </h3>
        </div>

        <div class="tab-content mod-content">
        <form action="admin/ajax/weixin/send_msg/" id="msg_form" method="post" onsubmit="return false" enctype="multipart/form-data">
            <table class="table table-striped">
                <tr>
                    <td>
                        <div class="form-group">
                            <span class="col-sm-4 col-xs-3 control-label"><?php _e('目标分组'); ?>:</span>
                            <div class="col-sm-5 col-xs-8">
                                <select name="group_id" class="form-control">
                                   <?php foreach ($this->groups AS $group_info) { ?>
                                       <option value="<?php echo $group_info['id']; ?>"><?php echo $group_info['name']; ?></option>
                                   <?php } ?>
                               </select>
                            </div>
                        </div>
                    </td>
                </tr>

                <tr>
                    <td>
                        <div class="form-group">
                            <span class="col-sm-4 col-xs-3 control-label"><?php _e('封面标题'); ?>:</span>
                            <div class="col-sm-5 col-xs-8">
                                <input class="form-control" name="main_msg_title" type="text" value="" />
                            </div>
                        </div>
                    </td>
                </tr>

                <tr>
                    <td>
                        <div class="form-group">
                            <span class="col-sm-4 col-xs-3 control-label"><?php _e('封面作者'); ?>:</span>
                            <div class="col-sm-5 col-xs-8">
                                <input class="form-control" name="main_msg_author" type="text" />
                            </div>
                        </div>
                    </td>
                </tr>

                <tr>
                    <td>
                        <div class="form-group">
                            <span class="col-sm-4 col-xs-3 control-label"><?php _e('封面内容'); ?>:</span>
                            <div class="col-sm-5 col-xs-8">
                                <textarea class="form-control textarea" name="main_msg_content" rows="10"></textarea>
                            </div>
                        </div>
                    </td>
                </tr>

                <tr>
                    <td>
                        <div class="form-group">
                            <span class="col-sm-4 col-xs-3 control-label"><?php _e('封面的原文链接'); ?>:</span>
                            <div class="col-sm-5 col-xs-8">
                                <input class="form-control" name="main_msg_url" type="text" value="" />
                            </div>
                        </div>
                    </td>
                </tr>

                <tr>
                    <td>
                        <div class="form-group">
                            <span class="col-sm-4 col-xs-3 control-label"><?php _e('封面图片'); ?>:</span>
                            <div class="col-sm-6">
                                <span class="mod-file">
                                    <input type="button" class="btn btn-primary" value="点击选择图片" />
                                    <input type="file" name="main_msg_img" exts="bmp|png|jpg|jpeg|gif" class="mod-input-file" />
                                </span>
                                <p class="filetext"></p>
                                <span class="help-block"><?php _e('图片支持 bmp/png/jpeg/jpg/gif 格式，最大为 2M'); ?></span>
                            </div>
                        </div>
                    </td>
                </tr>

                <tr>
                    <td>
                        <div class="form-group">
                            <span class="col-sm-4 col-xs-3 control-label"><?php _e('在正文中显示封面图片'); ?>:</span>
                            <div class="col-sm-6 col-xs-8">
                                <div class="btn-group mod-btn">
                                    <label type="button" class="btn mod-btn-color">
                                        <input type="radio" name="show_cover_pic" value="1" /> <?php _e('是'); ?>
                                    </label>

                                    <label type="button" class="btn mod-btn-color">
                                        <input type="radio" name="show_cover_pic" value="0" checked="checked" /> <?php _e('否'); ?>
                                    </label>
                                </div>
                            </div>
                        </div>
                    </td>
                </tr>

                <tr>
                    <td>
                        <div class="form-group">
                            <span class="col-sm-4 col-xs-3 control-label"><?php _e('增加问题'); ?>:</span>
                            <div class="col-sm-5 col-xs-8 mod-question">
                                <ul class="aw-question-list"></ul>
                                <input type="text" class="form-control search-input" placeholder="问题">
                                <div class="aw-dropdown">
                                    <p class="title">没有找到相关结果</p>
                                    <ul class="aw-dropdown-list">
                                        <li>
                                        </li>
                                    </ul>
                                </div>
                                <input class="question_ids collapse" name="question_ids" value="" type="hidden" />
                            </div>
                        </div>
                    </td>
                </tr>

                <tr>
                    <td>
                        <div class="form-group">
                            <span class="col-sm-4 col-xs-3 control-label"><?php _e('增加文章'); ?>:</span>
                            <div class="col-sm-5 col-xs-8 mod-article">
                                <ul class="aw-article-list"></ul>
                                <input type="text" class="form-control search-input" placeholder="文章">
                                <div class="aw-dropdown">
                                    <p class="title">没有找到相关结果</p>
                                    <ul class="aw-dropdown-list">
                                        <li>
                                        </li>
                                    </ul>
                                </div>
                                <input class="article_ids hide" name="article_ids" value="" type="hidden" />
                            </div>
                        </div>
                    </td>
                </tr>

                <tfoot>
                <tr>
                    <td>
                        <input type="button" value="<?php _e('保存设置'); ?>" class="btn btn-primary center-block postBtn" />
                    </td>
                </tr>
                </tfoot>
            </table>
        </form>
        </div>
    </div>
</div>

<script>
    $(function(){
        AWS.Dropdown.bind_dropdown_list($('.mod-question input'), 'adminQuestions');

        $('.aw-dropdown').delegate("a","click",function(){
            $(".search-input").val("");
        });

        AWS.Dropdown.bind_dropdown_list($('.mod-article input'), 'adminArticles');

        $('.aw-question-list').delegate('.btn-danger','click',function(){
            var tempStr =  $('.question_ids').val();
            $('.question_ids').val(tempStr.replace($(this).parents("li").attr('data-id')+ ',',''));
            $(this).parents("li").detach();
        });

        $('.aw-article-list').delegate('.btn-danger','click',function(){
            var tempStr =  $('.article_ids').val();
            $('.article_ids').val(tempStr.replace($(this).parents("li").attr('data-id')+ ',',''));
            $(this).parents("li").detach()
        });

        $('.mod-input-file').change(function(){
            $('.filetext').text($('.mod-input-file').val());
        });

        $('.postBtn').click(function(){
            AWS.dialog('confirm',{'message': '<?php _e('确定要群发消息吗？'); ?>'},function(){
                $('.modal-backdrop').css({display:'none'})
                AWS.ajax_post($('#msg_form'));
            })
        });
    })
</script>

<?php TPL::output('admin/global/footer.tpl.htm'); ?>